<!-- 疑问表单弹窗 -->
<form id="answer-form" lay-filter="answer-form" class="layui-form model-form">
	<input name="id" type="hidden" />
	<div class="layui-form-item">
		<label class="layui-form-label">疑问标题</label>
		<div class="layui-input-block">
			<input name="title" placeholder="请输入疑问标题" type="text" class="layui-input" maxlength="20" lay-verify="required"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">疑问内容</label>
		<div class="layui-input-block">
			<textarea name="content" placeholder="请输入疑问内容" type="text"style="height: 60px" class="layui-input"/>
		</div>
	</div>
	<div class="layui-form-item model-form-footer">
		<button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
		<button class="layui-btn" lay-filter="answer-form-submit" lay-submit>保存</button>
	</div>
</form>

<script>
	layui.use(['layer', 'admin', 'form','index'], function() {

		var layer = layui.layer;
		var admin = layui.admin;
		var form = layui.form;
		var index = layui.index;
		var login_user

		// 获取当前用户信息
		index.getUser(function (user) {
			login_user = user.username
		});

		// 回显answer数据
		var answer = admin.getTempData('answer');
		if (answer) {
			console.log(answer)
			form.val('answer-form', answer);
		}

		// 表单提交事件
		form.on('submit(answer-form-submit)', function(data) {
			console.log(data)
			layer.load(2);
			data.field.publisher = login_user ;
			admin.req('api-answer/answer/addAnswer', JSON.stringify(data.field), function (data) {
				layer.closeAll('loading');
				if (data.code == 0) {
					layer.msg(data.msg, {
						icon: 1,
						time: 2000
					});
					admin.finishPopupCenter();
				} else {
					layer.msg(data.msg, {
						icon: 2,
						time: 2000
					});
				}
			}, 'POST');
			return false;
		});

	});
</script>
